package com.zkingsoft.actions.admin.web;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import com.zkingsoft.services.web.WebProductCategoryService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.sys.SysFunction;
import com.zkingsoft.model.web.WebProductCategory;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.pojo.AjaxResult;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-15 14:22
 */
@Controller
@RequestMapping(value = "admin/webProductCategory")
public class WebProductCategoryController extends BaseController{

	@Resource
	private WebProductCategoryService webProductCategoryService;
	
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="WebProductCategory_BEV";
	
	public static final String fnCode = "WebProductCategory";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(WebProductCategory webProductCategory, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(webProductCategoryService, webProductCategory, pageVo);
	}
	/**
	 * 搜索
	 */
	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(WebProductCategory webProductCategory) {
		webProductCategory=webProductCategoryService.findById(webProductCategory.getPrcId());
		WebUtil.setSessionAttribute(BEV, webProductCategory);
		return new AjaxResult(AjaxResult.STATUS_OK, Arrays.asList(webProductCategory));
	}
	/**
	 * 显示所有功能
	 */
	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return new AjaxResult(AjaxResult.STATUS_OK, webProductCategoryService.findByModel(null));
	}
	/**
	 * 新增或者修改页面
	 */   
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(WebProductCategory webProductCategory) {
		if (webProductCategory.getPrcId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		webProductCategory.setPrcId(((WebProductCategory)WebUtil.getSessionAttribute(BEV)).getPrcId());
	   		AjaxResult result=modify(webProductCategoryService, WebUtil.getSessionAttribute(BEV), webProductCategory, "产品类别");
			//WebUtil.removeSessionAttribute(BEV);
	   		WebUtil.setSessionAttribute(BEV, webProductCategory);
			return  result;	
	
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(webProductCategoryService, webProductCategory, "产品类别");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		WebProductCategory webProductCategory;
		if (id != null) {
			webProductCategory = webProductCategoryService.findById(id);
			WebUtil.getRequest().setAttribute("obj", webProductCategory);
			WebUtil.setSessionAttribute(BEV, webProductCategory);
		}
		return "admin/web/WebProductCategory-form";
	}
   	
   	
   	/**
	 * 删除
	 */  

 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(Long prcId) {
 		matrixAdapter.isBtnPermitted(del);
		int i = webProductCategoryService.removeById(prcId);
		if (i > 0) {
			return new AjaxResult(AjaxResult.STATUS_OK, null, "成功删除" + i + "条数据");
		} else {
			return new AjaxResult(AjaxResult.STATUS_ERR, null, "删除失败");
		}
	}
 
}